function getlog(b, c) {
  if(b != false) {
    var a = arrayRow(2);
    if(a.length > 1 || a.length == 0) {
      alertGrowl(MISC_ERROR, VISU_ERROR_ENOUGHTSELECT);
      return false
    }
  }else {
    a = c;
  }
  $.post(baseUrl + "/log/log/", {model:$("#listModelLog :selected").text(), type:$("#listTypeLog :selected").text(), proto:$("#listProtocolLog :selected").text(), filtre:$("#listFiltreLog :selected").text(), identity:$("#listUserLog :selected").text(), ip:a.toString()}, attenteReponse, "json");
  return true
}
function enterKeyLog() {
  $(":input", diagLog).keypress(function(a) {
    if(a.which && a.which == 13 || a.keyCode && a.keyCode == 13) {
      diagLog.dialog("close");
      ajouterItem("Log", "log/");
      getlog()
    }
  })
}
function dialogLog() {
  if(tabulaireTable == undefined) {
    alertGrowl(MISC_ERROR, VISU_ERROR_EMPTYSEARCH)
  }else {
    getListFilter();
    var btns = {};
    btns[BUTTON_CANCEL] = function() {$(this).dialog("close")};
    btns[BUTTON_EXEC] =function() {$(this).dialog("close"); ajouterItem("Log", "log/"); getlog()};
    diagLog.dialog({autoOpen:false, draggable:true, width:"auto", modal:true, buttons:btns});
    diagLog.dialog("open");
  }
}
function getListFilter() {
  $.post(baseUrl + "/log/getlistfilter/", {}, selectFilterBaseFiltre, "json")
}
function removeLogTabulaire() {
  $("#divLogTab").find("*").remove();
  $("#divLogTab").append('<table  class="display" id="logTab"></table>')
}
function logTabulaireResp(a) {
  removeLogTabulaire();
  var logTable = $("#logTab");
  addTitleLog(a.aoColumns, logTable);
  logTable.dataTable({bFilter:false, bInfo:false, bAutoWidth:false, bLengthChange:false, bSort:false, bSortClasses:false, bSortable:false});
  addRowLog(a.aaData, logTable)
}
function addTitleLog(a, c) {
  c.append("<thead><tr></tr></thead>");
  for(var b = 0;b < a.length;b++) {
    $("#logTab thead tr").append("<th>" + a[b] + "</th>")
  }
  return true
}
function addRowLog(a, c) {
  for(var b = 0;b < a.length;b++) {
    var tmp = a[b].split(";;;");
    c.fnAddData(tmp)
  }
  return true
}
$(function() {
   var a = $("#boutonUtilisateur")
   $(a + "[b|=addFilter]").click(addFilterInput);
   $(a + "[b|=removeFilter]").click(removeFilterInput)
});
function addFilterInput(b, c) {
  idFilter++;
  if ( typeof b == 'undefined' || typeof c == 'undefined' ) {
      b = 'Colone';
      c = 'Filtre';
  }
  var a = '<input type="text" id="filterName' + idFilter + '" name="filterName' + idFilter + '" size="25" value="' + b + '" />';
  a += ' <input type="text" id="regExp' + idFilter + '" name="regExp' + idFilter + '" size="25" value="' + c + '" />';
  $("#inputLogFilterMenu").append(a);
  return true
}
function removeFilterInput() {
  $("#filterName" + idFilter).remove();
  $("#regExp" + idFilter).remove();
  idFilter--;
  return true
}
function getFilter() {
  for(var a = [], c = $("#logFilterMenu :text"), b = 1;b < c.length;b++) {
    var val = c[b].value;
    if(val == "Colone" || val == "Filtre" || val.length == null) {
      alertGrowl(MISC_ERROR, VISU_LOG_ERROR);
      return false
    }
    a.push("[{" + val + "}]")
  }
  return a
}
function checkNameFilter(a) {
  if(a.error == true) {
    updateFilter(a.name)
    return false
  }
   alertGrowl(VISU_LOG_TXT, VISU_LOG_ADD);
  return true
}
function updateFilter(a) {
    var b = getFilter();
    $.post(baseUrl + "/log/updatefilter/", {name:a, data:b.toString()}, alertGrowl(VISU_LOG_TXT, VISU_LOG_UPDATE), "json");
}
function createFilter() {
  var a = getFilter(), b = $("#nameFiltre");
  if(a.length == null) {
    return false
  }
  if(b.val().length == 0) {
    alertGrowl(MISC_ERROR, VISU_LOG_EMPTYNAME);
    return false
  }
  $.post(baseUrl + "/log/createfilter/", {name:b.val(), data:a.toString()}, checkNameFilter, "json");
  return true
}
function getListFilterOption() {
  $.post(baseUrl + "/log/getlistfilter/", {}, makeListFilter, "json")
}
function makeListFilter(a) {
    var b = $("#regExp"), h = [], e=$("#listFiltres");
    $("#nameFiltre").val("");
    $("#filterName").val("Colone");
    b.val("Filtre");
    b.nextAll('input').remove()
    e.empty();
    h[0] = "<option value='-'>-</option>"
    for(var c =0, d = a.filtre.length;c < d;c++) {
        if($(e + "option[value=" + a.filtre[c] + "]").length == 0) {
        h[c + 1] = "<option value='" + a.filtre[c].NameFilter + "'>" + a.filtre[c].NameFilter + "</option>"
    }
  }
  $(e).append(h.join(""))
  changeListFilter(e)
}
function changeListFilter(b) {
  $(b).change(function() {
    var a = $(this).val();
    loadFilter(a);
  })
}
function loadFilter(a) {
    $.post(baseUrl + "/log/geinfofilter/", {name:a}, updateListFilter, "json")
}
function updateListFilter(a) {
    var b = $("#regExp");
    $("#nameFiltre").val(a.name);
    $("#filterName").val(a.list[0]);
    b.nextAll('input').remove();
    b.val(a.list[1])
    for ( var c = 3, d = a.list.length; c < d; c = c + 2 )
        addFilterInput(a.list[c - 1],a.list[c]);
}
function delFilterLog() {
    var a = $("#listFiltres :selected").val();
    if (a == '-')
        return false;
    $.ajax({type:"POST", url:baseUrl + "/log/delfiltre/", success:alertGrowl(VISU_LOG_TXT, VISU_LOG_DEL), dataType:"json", async:false, data:({filtre:a})});
    getListFilterOption()
}
valid.add("delFilterLog", delFilterLog);
function dialogFilter() {
  getListFilterOption()
  var a = $("#dialogFilter");
  var btns = {};
  btns[BUTTON_CANCEL] = function() {$(this).dialog("close")};
  btns[BUTTON_CREATE_FILTER] = function() {$(this).dialog("destroy"); createFilter()};
  a.dialog({autoOpen:false, draggable:true, width:440, modal:true, buttons:btns});
  a.dialog("open")
}
